package cn.ztelovecly.springboot.framework.message;

import cn.ztelovecly.springboot.framework.util.SettingUtil;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;

public abstract class ConsumerMessage {

    private static String postfix = SettingUtil.getProperty("", "mq.topic.postfix").toUpperCase();
    private static String prefix = SettingUtil.getProperty("", "mq.topic.prefix").toUpperCase();

    /**
     * 消息主题
     */
    private String msg_topic;

        /**
         * 获取消息Topic
         * @return
         */
       public String getTopic(){
           if (postfix == null || postfix.equals("") || postfix.equals("NONE")) {
               postfix = "";
           } else {
               if (!postfix.startsWith("_")){
                   postfix = "_" + postfix;
               }
           }
           if (prefix == null || prefix.equals("") || prefix.equals("NONE")) {
               prefix = "";
           } else {
               if (!prefix.endsWith("_")){
                   prefix = prefix + "_";
               }
           }
           return prefix + msg_topic + postfix;
//           if(postfix==null || postfix.equals("") || postfix.equals("NONE")) {
//               return msg_topic;
//           }else{
//               return msg_topic+"_"+postfix;
//           }
       }

    public void setMsg_topic(String topic){
        this.msg_topic = topic;
    }

        /**
         * 获取消息Tag
         * @return
         */
       public abstract String getTag();

        /**
         * 处理消息
         * @param message
         * @return
         */
        public abstract  ConsumeConcurrentlyStatus consumerMessage(String message);


}
